/*
 *  $Id: MagicFetters.cs 1063 2010-05-20 17:40:43Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Water.Spells {
    public class MagicFetters: TargetEnchantmentCard<Creature> {
        public MagicFetters(): base("001_w_s_magic_fetters") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Water;
            Value = 100;
            Target = CreatureTarget.Both;
            AddManaCost(ElementType.Water, 3);
        }

        protected override EnchantmentAffect CreateEnchantment() {
            return new MagicFettersAffect();
        }

        private class MagicFettersAffect: EnchantmentAffect<MagicFetters> {
            private bool _active;

            public MagicFettersAffect(): base(true) {
                DefaultDescription = true;
                _active = false;
            }


            public override Languages.Phrase Description {
                get { return _active ? base.Description : BaseCard.Description; }
            }

            public override void SetAffect() {
                base.SetAffect();
                if (!_active) LocalSummary.OnUseAbility += DoMagicFetters;
            }
            public override void ResetAffect() {
                base.ResetAffect();
                if (!_active) LocalSummary.OnUseAbility -= DoMagicFetters;
            }

            public override void Dispell() {
                if (!_active) {
                    LocalSummary.ChangeDamage(-1);
                    LocalSummary.ChangeMaxHealth(-1);
                }
                base.Dispell();
            }

            private void DoMagicFetters(AbilityCard ability, TargetArgs args) {
                if (_active) return;
                ResetAffects();
                Add(new Affects.Idler());
                Add(new Affects.Antimagic());
                _active = true;
                SetAffects();
                UpdateDescription();
            }
        }
    }
}
